#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include "ToolBox.h"
#include "Tool.h"
#include "Map.h"
#include "Button.h"
#include "OuvrirButton.h"
#include "EnregistrerButton.h"
#include "EditText.h"
#include "MapLoader.h"

using namespace std;
using namespace sf;

int main()
{

    RenderWindow app(sf::VideoMode(800, 600, 32), "Map Creator !", Style::Close);

    app.SetFramerateLimit(60);


	Map monde(250,85);


    ToolBox boite(20,85);

    Tool sol1("images/sol1.png", false);
    Tool sol2("images/sol2.png", false);
    Tool ocean1("images/ocean1.png", false);
    Tool sable1("images/sable1.png", false);
    Tool arbre1("images/arbre1.png", true);
    Tool foret1("images/foret.png", true);
    Tool haie("images/haie.png", true);
    Tool banc1("images/banc1.png", true);
    Tool rock1("images/rock.png", true);
    Tool pierre("images/pierre.png", true);
    Tool fleur("images/fleur.png", true);
    Tool wall1("images/wall1.png", true);
    Tool fontaine("images/fontaine.png", true);

    EditText edit(2, 2,610);
    edit.setPlaceHolder("Chemin/nomdufichier");

    EnregistrerButton enregistrer(30,104,616,2);
    enregistrer.setText("Enregistrer", 18);
    enregistrer.setBackgroundColor(Color::White);

    OuvrirButton ouvrir(30,74, 724,2);
    ouvrir.setText("Ouvrir", 18);
    ouvrir.setBackgroundColor(Color::White);

    while (app.IsOpened())
    {

        Event event;
        while (app.GetEvent(event))
        {
            if (event.Type == Event::Closed)
                app.Close();
            else if(event.Type == Event::MouseButtonPressed){
                boite.setEvent(event);
                monde.setEvent(event);
                MapLoader::setFileName(edit.getText());
                MapLoader::setMap(monde);
            }
            enregistrer.setEvent(event);
            ouvrir.setEvent(event);
            edit.setEvent(event);
        }

        app.Clear(Color(200,200,200));

        //app.SetView(view1);
        monde.drawMap(app);

        //app.SetView(view2);
        boite.drawToolBox(app);

        ouvrir.drawButton(app);
        enregistrer.drawButton(app);

        edit.drawEditText(app);

        app.Display();
    }


    return EXIT_SUCCESS;
}

